package com.luochen.cdpt.util;

import org.springframework.beans.BeanUtils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class CollectionUtils extends org.springframework.util.CollectionUtils {
    /**
     * 复制集合值
     * @param sources
     * @param clazz
     * @param <S>
     * @param <T>
     * @return
     * @throws IllegalAccessException
     * @throws InstantiationException
     */
    public static <S,T>  List<T> copyProperties(Collection<S> sources ,Class<T> clazz) throws IllegalAccessException, InstantiationException {
        List<T> result = new ArrayList<>(sources.size());
        if (org.springframework.util.CollectionUtils.isEmpty(sources)){
            return result;
        }
        T target ;
        for (S source : sources) {
            target = clazz.newInstance();
            BeanUtils.copyProperties(source,target);
            result.add(target);
        }
        return result;
    }
}
